import { _decorator, CircleCollider2D, Component, EventTouch, Node, RigidBody2D } from 'cc';
import { Globals } from './Globals';
const { ccclass, property } = _decorator;

@ccclass('PinActrion')
export class PinActrion extends Component {
    
    start() {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
        // this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        // this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    update(deltaTime: number) {
        
    }

    onTouchStart(event: EventTouch) {
        // this.node.removeFromParent();
        
        if(!Globals.MainAction.layerCatAction.putPin(this)){
            Globals.MainAction.layerSlotAction.putPin(this);
        }
        
    }

    removeCollider(){
        this.node.getComponent(CircleCollider2D).enabled = false;
        this.node.getComponent(RigidBody2D).enabled = false;
    }
        
    // onTouchMove(event: EventTouch) {
    //     // 获取触摸点在节点上的位置 
    //     const touchPos = event.getLocation();
        
    // }

    // onTouchEnd(event: EventTouch) {
    //     // 获取触摸点在节点上的位置
    //     const touchPos = event.getLocation();
        
    // }

    onDestroy(){
        this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
        // this.node.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        // this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }




}


